subroutine r2abij_t2aeim_wmbej(r2, t2, wmbej, & 
               icore, fact)
!
use mod_ioff
use mod_size
use mod_iop
use mod_orbit 
implicit none
!
real*8, intent(in) :: fact
real*4, intent(in) :: r2(*)
real*4, intent(in) :: wmbej(*)
!
real*4, intent(inout) :: t2(*), icore(*)
!
integer :: i, j, a, b, nsize
integer :: i0, i1, i2, i3
integer, external :: idsymsoc
real*8, external :: dnrm2
!this is to do r2(ab,ij) = r2(abij) + Pab*Pij*t2(ae,im)*w(embj)
i0 = 1                 
i1 = i0 + nvvoo*isd 
i2 = i1 + nvvoo*isd   
i3 = i2 + nvvoo*isd
!--------------------------------------------------------------------
!
! R2ABABR: SUM_mn T2AA(AE,IM)W(EM,bj)+T2AB(Ae,Im)W(embj)
!                +T2AB(Eb,Mj)W(EM,AI)+T2BB(be,jm)W(emAI)
!                -T2AB(Eb,Im)W(Em,Aj)*2
!                -T2AB(Ae,Mj)W(eM,bI)*2
!
 call myicopyso(t2(ioi3(2)), icore(i0), nioi32)
 call isymtrso(t2(ioi3(2)), icore(i1), vrta, vrta, 1, 1, popa, popa, 1, 0, 1)
 call axpyso(nioi32, -1.d0, icore(i1), 1, icore(i0), 1)
!
!CALL IEXPSO(T2(ioi3(1)), ICORE(i1), vrta, vrta, 0, 1, popa, popa, 0, 0, 1)
!CALL IEXPSO(icore(i1),  ICORE(i0), vrta, vrta, 1, 0, popa, popa, 0, 1, 1)
 CALL SSTGENSO(ICORE(i0), ICORE(i1), nsize, vrta, vrta, &
             popa, popa, ICORE, 1, '1324')
 CALL VpqmnVmnrs_to_Vpqrs(ICORE(i1), WMBEJ(ioi4(5)), 1, 1, &
                vrta, popa, 1, vrta, popa, 1, &
                vrtb, popb, 1, icore(i2), 1, 1.d0, 0.d0)
 call itranspso(icore(i2), icore(i1), vrta, popa, 1, vrta, popa, 1, 1)
 call axpyso(nioi32, 1.d0, icore(i1), 1, icore(i2), 1)
!
 CALL SSTGENSO(T2(ioi3(2)), ICORE(i1), nsize, vrta, vrtb, &
             popa, popb, icore, 1, '1324')
 CALL VpqmnVmnrs_to_Vpqrs(ICORE(i1), WMBEJ(ioi4(1)), 1, 1, &
                vrtb, popb, 1, vrta, popa, 1, &
                vrtb, popb, 1, icore(i0), 1, 1.d0, 0.d0)
 CALL axpyso(nioi32, 1.d0, icore(i0), 1, icore(i2), 1)
 call itranspso(icore(i0), icore(i1), vrta, popa, 1, vrta, popa, 1, 1) 
 CALL axpyso(nioi32, 1.d0, icore(i1), 1, icore(i2), 1)
  
!
!CALL VmnpqVmnrs_to_Vpqrs(WMBEJ(ioi4(1)), ICORE(i1), 1, 1, &
!               vrta, popa, 1, vrta, popa, 1, &
!               vrtb, popb, 1, icore(i2), 1, 1.d0, 1.d0)
!
!CALL IEXPSO(T2(ioi3(3)), ICORE(i1), vrtb, vrtb, 0, 1, popb, popb, 0, 0,1)
!CALL IEXPSO(icore(i1), ICORE(i0), vrtb, vrtb, 1, 0, popb, popb, 0, 1,1)
!CALL SSTGENSO(ICORE(i0), ICORE(i1), nsize, vrtb, vrtb, &
!            popb, popb, ICORE, 1, '1324')
!CALL VmnpqVmnrs_to_Vpqrs(WMBEJ(ioi4(5)), ICORE(i1), 1, 1, &
!               vrtb, popb, 1, vrta, popa, 1, &
!               vrtb, popb, 1, icore(i2), 1, 1.d0, 1.d0)
!
 CALL SSTGENSO(icore(i2), icore(i1), nsize, &
           vrta, popa, vrtb, popb,ICORE,1,'1324')
 CALL AXPYSO(nioi32, fact, ICORE(i1), 1, R2(ioi3(2)), 1)
!
!           -T2AB(Eb,Im)W(Em,Aj)
!           -T2AB(Ae,Mj)W(eM,bI)
 CALL SSTGENSO(T2(ioi3(2)), ICORE(i1), nsize, vrta, vrtb, &
                popa, popb, ICORE, 1, '2314')
 CALL VpqmnVmnrs_to_Vpqrs(ICORE(i1), WMBEJ(ioi4(2)), 1, 1, &
                vrta, popb, 1, vrtb, popa, 1, &
                vrta, popb, 1, icore(i2), 1, 1.d0, 0.d0)
 CALL itranspso(icore(i2), icore(i1), vrta, popa, 1, vrta, popa, 1, 1)
 call axpyso(nioi32, 1.d0, icore(i1), 1, icore(i2), 1)
!
!CALL VmnpqVmnrs_to_Vpqrs(WMBEJ(ioi4(2)), ICORE(i1), 1, 1, &
!               vrtb, popa, 1, vrtb, popa, 1, &
!               vrta, popb, 1, icore(i2), 1, 1.d0, 1.d0)
!
 CALL SSTGENSO(icore(i2), ICORE(i1),nsize, &
               vrtb, popa, vrta, popb, ICORE,1,'3124')
 CALL AXPYSO(nioi32, fact, ICORE(i1), 1, R2(ioi3(2)), 1)
!
!----------------------------------------------------------------------
!
return
end
